package operation;
import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2024-06-04
 * Time: 21:54
 */
public class AddBooks implements IBooks{
    @Override
    public void work(BookList booklist){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名");
        String name = scanner.nextLine();
        System.out.println("请输入作者");
        String auther = scanner.nextLine();
        System.out.println("请输入价格");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入书的类型");
        String type = scanner.nextLine();
        Book book = new Book(name,auther,price,type);
        int count = booklist.getUsedSize();
        for (int i = 0; i < count; i++) {
            Book book1 = booklist.getBook(i);
            if(book1.getName().equals(name)){
                System.out.println("已经存在这本书，不能在进行添加了");
                return;
            }
        }
        booklist.setBooks(count,book);
        booklist.setUsedSize(count+1);
        System.out.println("添加成功！");
    }
}
